//
//  TJTemplateMultipleDetailCell.m
//  BaoDian
//
//  Created by mac on 2024/8/4.
//

#import "TJTemplateMultipleDetailCell.h"
#import "TJVideoCoverDownloader.h"

@interface TJTemplateMultipleDetailCell()

@property (nonatomic, weak) UIImageView *coverImageView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *dateLabel;


@end



@implementation TJTemplateMultipleDetailCell

- (void)settingSubView {
    [super settingSubView];
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = UIColor.tj_backgroundColor;
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.backgroundColor = UIColor.tj_1E1F23Color;
    tj_contentView.addCornerRadius(12);
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.inset(16);
        make.top.offset(0);
    }];
    
    UIImageView *coverImageView = [UIImageView addToView:self.contentView];
    coverImageView.addCornerRadius(8);
    coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    [coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.width.height.offset(50);
        make.centerY.offset(0);
    }];
    
    UIImageView *playerIconView = [UIImageView addToView:coverImageView];
    playerIconView.image = [UIImage imageNamed:@"videoPlayer_icon"];
    [playerIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
        make.width.height.offset(24);
    }];

    UILabel *titleLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontSemiboldMake(16) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentCenter];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(coverImageView.mas_right).offset(10);
        make.top.equalTo(coverImageView).offset(3);
        make.right.mas_lessThanOrEqualTo(-90);
    }];
    
    UILabel *dateLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(12) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentCenter];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset(4);
    }];
    
    UIButton *clockInButton = [UIButton buttonWithSuperView:tj_contentView font:UIFontMake(12) color:UIColor.whiteColor title:@"去打卡"];
    clockInButton.addCornerRadius(15);
    [clockInButton addTarget:self action:@selector(didClickClockInButton) forControlEvents:UIControlEventTouchUpInside];
    clockInButton.backgroundColor = UIColorMake(0x2978F0);
    [clockInButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.inset(16);
        make.width.offset(60);
        make.height.offset(30);
    }];
    
    _coverImageView = coverImageView;
    _dateLabel = dateLabel;
    _titleLabel = titleLabel;
}

- (void)didClickClockInButton {
    if (_didClickClockButtonBlock) {
        _didClickClockButtonBlock();
    }
}

- (void)setModel:(TJTemplateModel *)model {
    _model = model;
    
    _titleLabel.text = model.videoName;
    _dateLabel.text = model.dataDate;
    
    [[TJVideoCoverDownloader shareDownLoader] downloadWithUrl:model.videoUrl completion:^(UIImage * _Nullable thumbnail) {
        self.coverImageView.image = thumbnail;
    }];
}


@end
